import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

/**
 * JUnit测试运行器
 * 使用JUnit完成类的单元测试
 */
public class TestRunner {
    public static void main(String[] args) {
        System.out.println("JUnit单元测试开始");
        System.out.println("========================");
        
        // 运行JUnit测试
        Result result = JUnitCore.runClasses(ExpressionJUnitTest.class);
        
        // 输出测试结果
        System.out.println("测试报告:");
        System.out.println("总测试数: " + result.getRunCount());
        System.out.println("失败数: " + result.getFailureCount());
        System.out.println("运行时间: " + result.getRunTime() + "ms");
        
        if (result.wasSuccessful()) {
            System.out.println("所有JUnit测试通过！");
        } else {
            System.out.println("失败的测试:");
            for (Failure failure : result.getFailures()) {
                System.out.println(" - " + failure.getTestHeader());
                System.out.println("   原因: " + failure.getMessage());
            }
        }
        
        System.out.println("========================");
    }
}